package Explorer.Exp2;

import java.util.ArrayList;

public class Chemin {
	
	private String depart;
	private ArrayList<String> listNoeud;
	private int poids;
	private ArrayList<String> visitedNode;
	private boolean fin;
	public Chemin(String idNoeud, int poids)
	{
		this.poids = poids;
		depart = idNoeud;
		listNoeud = new ArrayList<String>();
		visitedNode = new ArrayList<String>();
		fin = false;
	}
	
	public Chemin(String id)
	{
		this(id,0);
	}
	
	public Chemin()
	{
		this.poids = 0;
		this.listNoeud = new ArrayList<String>();
		this.visitedNode = new ArrayList<String>();
		this.fin = false;
		this.depart = "";
	}
	
	public void addNoeud(String id, int poids)
	{
		this.poids += poids;
		this.listNoeud.add(id);
		this.visitedNode.add(id);
	}
	

	public Chemin newFrom(String nodeDisable)
	{
		Chemin c = new Chemin();
		c.poids = this.poids;
		c.depart = depart;
		c.listNoeud = (ArrayList<String>)(this.listNoeud.clone());
		c.visitedNode = (ArrayList<String>)this.visitedNode.clone();
		c.visitedNode.add(this.getDernierNoeud());
		this.visitedNode.add(nodeDisable);
		
		return c;
	}
	
	public int getPoids()
	{
		return this.poids;
	}
	
	public String getDernierNoeud()
	{
		if(listNoeud.size() > 0)
			return listNoeud.get(listNoeud.size()-1);
		else 
			return depart;
	}
	
	public ArrayList<String> getListNoeud()
	{
		return this.listNoeud;
	}
	
	public boolean isNodeVisited(String id)
	{
		return visitedNode.contains(id);
	}
	
	public boolean completementVisite(Noeud n)
	{
		boolean b = true;
		for(Arete a : n.getAretes())
		{
			b = b && visitedNode.contains(a.getArrive().getName());
		}
		return b;
	}
	
	public void setFini()
	{
		fin = true;
	}
	
	public boolean getFini()
	{
		return fin;
	}
	
	public void setVisited(String id)
	{
		visitedNode.add(id);
	}
	public String getDepart()
	{
		return this.depart;
	}
}
